home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / progwin.zip / POPPAD1.ZIP / POPPAD1.C < prev    next >
Text File  |  1991-10-07  |  2KB  |  88 lines

  1.  /*-------------------------------------
  2.  
  3.   POPPAD1.C -- Popup Editor Using Child Window Edit Box
  4.          (c) Charles Petzold, 1990
  5.  ---------------------------------------*/
  6.  #include <windows.h>
  7.  
  8.  long FAR PASCAL WndProc (HWND, WORD, WORD, LONG);
  9.  char szAppName[] = "PopPad1" ;
  10.  int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  11.               LPSTR lpszCmdLine, int nCmdShow)
  12.        {
  13.        HWND        hwnd;
  14.        MSG       msg;
  15.        WNDCLASS       wndclass;
  16.  
  17.        if (!hPrevInstance)
  18.         {
  19.         wndclass.style     = CS_HREDRAW | CS_VREDRAW;
  20.         wndclass.lpfnWndProc = WndProc;
  21.         wndclass.cbClsExtra     = 0;
  22.         wndclass.cbWndExtra     = 0;
  23.         wndclass.hInstance     = hInstance;
  24.         wndclass.hIcon     = LoadIcon (NULL,IDI_APPLICATION);
  25.         wndclass.hCursor     = LoadCursor (NULL, IDC_ARROW);
  26.         wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  27.         wndclass.lpszMenuName  = NULL;
  28.         wndclass.lpszClassName = szAppName;
  29.  
  30.         RegisterClass (&wndclass);
  31.         }
  32.  
  33.        hwnd = CreateWindow (szAppName, szAppName,
  34.                 WS_OVERLAPPEDWINDOW,
  35.                 CW_USEDEFAULT,CW_USEDEFAULT,
  36.                 GetSystemMetrics (SM_CXSCREEN) / 2,
  37.                 GetSystemMetrics (SM_CYSCREEN) / 2,
  38.                 NULL, NULL, hInstance, NULL) ;
  39.  
  40.        ShowWindow (hwnd, nCmdShow);
  41.        UpdateWindow (hwnd);
  42.  
  43.        while (GetMessage (&msg, NULL, 0, 0))
  44.         {
  45.         TranslateMessage (&msg);
  46.         DispatchMessage (&msg);
  47.         }
  48.        return msg.wParam;
  49.        }
  50.  
  51.   long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  52.        {
  53.     static HWND hwndEdit ;
  54.  
  55.     switch (message)
  56.         {
  57.         case WM_CREATE :
  58.          hwndEdit = CreateWindow ( " edit ", NULL,
  59.                 WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  60.                 WS_BORDER | ES_LEFT | ES_MULTILINE|
  61.                 ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  62.                 0,0,0,0,
  63.                 hwnd,1,
  64.                 ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
  65.                 return 0 ;
  66.  
  67.         case WM_SETFOCUS :
  68.          SetFocus (hwndEdit) ;
  69.          return 0;
  70.  
  71.         case WM_SIZE :
  72.          MoveWindow (hwndEdit, 0, 0, LOWORD(lParam),
  73.                 HIWORD(lParam), TRUE) ;
  74.          return 0;
  75.  
  76.         case WM_COMMAND:
  77.         if(wParam == 1 && HIWORD( lParam ) == EN_ERRSPACE)
  78.             MessageBox (hwnd,"Edit control out of space.",
  79.                 szAppName,MB_OK | MB_ICONSTOP );
  80.         return 0;
  81.  
  82.         case WM_DESTROY:
  83.         PostQuitMessage(0);
  84.         return 0;
  85.          }
  86.        return DefWindowProc (hwnd,message,wParam,lParam);
  87.        }
  88.